<?php

namespace app\api\controller;


class User
{
    public $pagesize = 10;
    public $default_group_id = 4;//前端新用户注册默认的系统角色组


    public function updateName()
    {
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        $nickname = trim(input("request.nickname"));//用户auth
        $dataModel = new \app\admin\model\User();
        $res = $dataModel->updateDataForWhere(array(
            'nickname' => $nickname,
        ), array('id' => $userInfo['id']));

        if($res ||$res ==0){
            $return = ['err' =>0, 'msg' => '操作成功', 'devMsg' => '操作成功'];
            return json($return);
        }else
        {
            $return = ['err' => 1, 'msg' => '操作失败', 'devMsg' => '操作失败'];
            return json($return);
        }

    }
    /**
     *
     * 用户名密码登录
     * http://127.0.0.1:9093/api/user/login?uname=15982398002&pwd=123456
     *
     */
    public function login()
    {
        $ver = trim(input("request.ver"));//app版本
        $imei = trim(input("request.imei"));//imei
        $os = trim(input("request.os"));//系统
        if ($os) {
            $os = strtolower($os);
        }
        $uname = trim(input("request.tel"));//
        if (empty($uname)) {
            $return = [
                'err' => 100, 'msg' => '登录失败', 'devMsg' => '登录失败，参数错误[uname]',
                'e_msg' => 'Login failed'
            ];
            return json($return);
        }
        $pwd = trim(input("request.pwd"));//
        if (empty($pwd)) {
            $return = ['err' => 100, 'msg' => '登录失败', 'devMsg' => '登录失败，参数错误[pwd]'
                , 'e_msg' => 'Login failed'];
            return json($return);
        }
        $userModel = new \app\admin\model\User();
        $where = array();
        $where['uname'] = $uname;
        $where['is_delete'] = 0;
        $userinfo = $userModel->getDataForWhere($where, '*');
        if (empty($userinfo)) {
            $return = ['err' => 1000, 'msg' => '登录失败,用户不存在', 'devMsg' => '登录失败，系统未检测到相关用户', 'e_msg' => 'Login failed'];
            return json($return);
        }
        $pwd = UserPwdE($pwd);
        if ($userinfo['pwd'] != $pwd) {
            $return = ['err' => 1000, 'msg' => '登录失败,密码错误', 'devMsg' => '登录失败，密码错误', 'e_msg' => 'The password is incorrect'];
            return json($return);
        }
        if ($userinfo['stat'] != 0) {
            $return = ['err' => 1000, 'msg' => '登录失败,账号被禁用', 'devMsg' => '登录失败，账号被禁用', 'e_msg' => 'Account disabled'];
            return json($return);
        }
        //记录登录日志
        $logdata = array(
            'ip' => get_client_ip(),
            'ctime' => time(),
            'uid' => $userinfo['id'],
            'ver' => $ver,
            'os' => $os,
            'imei' => $imei,
        );
        RecordLoginLog("loginlog", $logdata);

        $userinfo = filterUserInfoField($userinfo);
        //获取默认房价ID
        $defaultRoom = (new \app\admin\model\NewwindRoom())->getDataForWhere(['uid'=>$userinfo['id'],'flags'=>1]);
        $userinfo['default_room_id']=$defaultRoom['id'];
        $return = ['err' => 0, 'msg' => '登录成功', 'devMsg' => '登录成功', 'data' => $userinfo, 'e_msg' => 'Login successful'];
        $authConfig = array(
            'id' => $userinfo['id'],
            'uname' => $userinfo['uname'],
            'nickname' => $userinfo['nickname'],
            'time' => time(),
        );
        $return['auth'] = userAuth($authConfig);
        //记录登录信息
        recordClientVerAndType($userinfo, $_REQUEST['os'], $_REQUEST['ver']);
        return json($return);

    }


    /**
     * 微信openid登录接口
     * @return \think\response\Json
     */
    public function loginForWxOpenid()
    {
        $ver = trim(input("request.ver"));//app版本
        $imei = trim(input("request.imei"));//imei
        $os = trim(input("request.os"));//系统
        if ($os) {
            $os = strtolower($os);
        }
        $openid = trim(input("request.openid"));//
        if (empty($openid)) {
            $return = ['err' => 100, 'msg' => '登录失败', 'devMsg' => '登录失败，参数错误[openid]'];
            return json($return);
        }

        $userModel = new \app\admin\model\User();
        $where = array();
        $where['wechat_openid'] = $openid;
        $where['is_delete'] = 0;
        $userinfo = $userModel->getDataForWhere($where, '*');
        if (empty($userinfo)) {
            $return = ['err' => 1000, 'msg' => '登录失败,用户未绑定微信', 'devMsg' => '登录失败，用户未绑定微信'];
            return json($return);
        }

        if ($userinfo['stat'] != 0) {
            $return = ['err' => 1001, 'msg' => '登录失败,账号被禁用', 'devMsg' => '登录失败，账号被禁用'];
            return json($return);
        }
        //记录登录日志
        $logdata = array(
            'ip' => get_client_ip(),
            'ctime' => time(),
            'uid' => $userinfo['id'],
            'ver' => $ver,
            'os' => $os,
            'imei' => $imei,
        );
        RecordLoginLog("loginlog", $logdata);

        $userinfo = filterUserInfoField($userinfo);
        $return = ['err' => 0, 'msg' => '登录成功', 'devMsg' => '登录成功', 'data' => $userinfo];
        $authConfig = array(
            'id' => $userinfo['id'],
            'uname' => $userinfo['uname'],
            'nickname' => $userinfo['nickname'],
            'time' => time(),
        );
        $return['auth'] = userAuth($authConfig);
        //记录登录信息
        recordClientVerAndType($userinfo, $_REQUEST['os'], $_REQUEST['ver']);
        return json($return);
    }

    /**
     * 发送短信
     * @return \think\response\Json
     */
    public function rcode()
    {
        $type = trim(input("request.type"));//1注册  2找回密码 3 快捷登录  4、绑定支付宝提现账号 5、绑定微信
        $tel = trim(input("request.tel"));//手机号

        $ver = trim(input("request.ver"));//
        $imei = trim(input("request.imei"));//
        $os = trim(input("request.os"));//

        if (empty($type)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,短信类型错误';
            return json($return);
        }

        if (!checkPhone($tel)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }


        if ($type == 1) {
            $userModel = new \app\admin\model\User();
            $cuserInfo = $userModel->getDataForWhere(array(
                'uname' => $tel,
                'is_delete'=>0
            ));
            if ($cuserInfo) {
                $return['err'] = 10001;
                $return['msg'] = '该手机号已经注册';
                return json($return);
            }
        }
//网易发送短信验证码  1
//        $smsg = sendPhoneMsg($tel);
//        $code = 0;
//        if ($smsg['code'] == 200) {
//            $code = $smsg['obj'];
//        } else {
//            $return['err'] = 10001;
//            $return['msg'] = '短信发送失败';
//            return json($return);
//        }
//腾讯发送短信验证码  2
        $code = rand(1000, 9999);
        if ($tel == "13800138000" || $tel == "13800138001") {
            $code = "8888";
        }
        $res = tengxunPhoneSend($tel, $code);
        if ($res == false) {
            $return['err'] = 1;
            $return['msg'] = '发送失败';
            return json($return);
        }


        $tmsgcodeModel = new \app\admin\model\Tmsgcode();
        $data = array(
            'tel' => $tel,
            'types' => $type,
            'codes' => $code,
            'mtime' => time(),
            'uses' => 0
        );
        $res = $tmsgcodeModel->add($data);
        if ($res) {
            $return['err'] = 0;
            $return['msg'] = '发送成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '发送失败';
            return json($return);
        }
    }


    /**
     * 微信小程序 发送验证码
     * @return \think\response\Json
     */
    public function wechatrcode()
    {
        $type = trim(input("request.type"));//1注册  2找回密码 3 快捷登录  4、绑定支付宝提现账号 5、绑定微信
        $tel = trim(input("request.tel"));//手机号

        $ver = trim(input("request.ver"));//
        $imei = trim(input("request.imei"));//
        $os = trim(input("request.os"));//

        if (empty($type)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,短信类型错误';
            return json($return);
        }

        if (!checkPhone($tel)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }


        if ($type == 1) {
            $userModel = new \app\admin\model\User();
            $cuserInfo = $userModel->getDataForWhere(array(
                'uname' => $tel
            ));
            if ($cuserInfo) {
                $return['err'] = 10001;
                $return['msg'] = '该手机号已经注册';
                return json($return);
            }
        }

//        $smsg = sendPhoneMsg($tel);
//        $code = 0;
//        if ($smsg['code'] == 200) {
//            $code = $smsg['obj'];
//        } else {
//            $return['err'] = 10001;
//            $return['msg'] = '短信发送失败';
//            return json($return);
//        }

        $code = rand(1000, 9999);
        $res = tengxunPhoneSend($tel, $code);
        if ($res == false) {
            $return['err'] = 1;
            $return['msg'] = '发送失败';
            return json($return);
        }

        $tmsgcodeModel = new \app\admin\model\Tmsgcode();

        $data = array(
            'tel' => $tel,
            'types' => $type,
            'codes' => $code,
            'mtime' => time(),
            'uses' => 0
        );
        $res = $tmsgcodeModel->add($data);
        if ($res) {
            $return['err'] = 0;
            $return['msg'] = '发送成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '发送失败';
            return json($return);
        }
    }


    public function accountReg()
    {
        $uname = trim(input("request.uname"));//手机号
        $pwd = trim(input("request.pwd"));//
        $ver = trim(input("request.ver"));//
        $imei = trim(input("request.imei"));//手机imei
        $os = trim(input("request.os"));//手机系统

        if ($os) {
            $os = strtolower($os);
        }

        $dataModel = new \app\admin\model\User();

        if (empty($uname)) {
            $return['err'] = 11000;
            $return['msg'] = '请输入账号';
            $return['e_msg'] = 'Account number cannot be empty';
            return json($return);
        }

        if (strlen($uname) < 6) {
            $return['err'] = 11000;
            $return['msg'] = '账号长度不够';
            $return['e_msg'] = 'Account length is not enough';
            return json($return);
        }
        if (empty($pwd)) {
            $return['err'] = 11000;
            $return['msg'] = '密码不能为空';
            $return['e_msg'] = 'Password  number cannot be empty';
            return json($return);
        }

        if (strlen($pwd) < 6) {
            $return['err'] = 11000;
            $return['msg'] = '密码长度不够';
            $return['e_msg'] = 'Password length is not enough';
            return json($return);
        }


        $userInfo = $dataModel->getDataForWhere(array(
            'uname' => $uname,
        ));


        if (!empty($userInfo)) {
            $return['err'] = 900000;
            $return['msg'] = '对不起，账号已经存在';
            $return['e_msg'] = 'Account already exists';
            return json($return);
        }

        $ipwd = userPWD($pwd);
        $tcode = trim(input("request.tcode"));//推广码
        $acode = trim(input("request.acode"));//代理编号
        $agentAndParent = userAgentAndParent($tcode, $acode);
        $idata = array(
            'uname' => $uname,
            'tcode' => str_rand(),//新建用户自己推广码
            'agent_id' => $agentAndParent['agent_id'],
            'father_id' => $agentAndParent['father_id'],
            'pwd' => $ipwd,
            'ver' => $ver,
            'os' => $os,
            'imei' => $imei,
            'ctime' => date("Y-m-d H:i:s"),
            'group' => $this->default_group_id//普通用户组
        );
        $res = $dataModel->add($idata);

        if ($res) {
            $userInfo = $idata;
            $userInfo['id'] = $res;
            //给用户增加默认角色,为支持多角色设计
            addUserSystemGroup($userInfo['id'], $this->default_group_id);
            $authConfig = array(
                'id' => $userInfo['id'],
                'uname' => $userInfo['uname'],
                'nickname' => $userInfo['nickname'],
                'time' => time(),
            );
            $return['auth'] = userAuth($authConfig);
            $return['err'] = 0;
            $return['msg'] = '注册成功';
            $return['e_msg'] = 'register was successful';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '注册失败';
            $return['e_msg'] = 'register has failed';
            return json($return);
        }
    }

    /**
     * 注册
     * @return \think\response\Json
     */
    public function reg()
    {
        $uname = trim(input("request.tel"));//手机号
        $pwd1 = trim(input("request.pwd1"));//
        $pwd2 = trim(input("request.pwd2"));//
        $code = trim(input("request.code"));//
        $ver = trim(input("request.ver"));//
        $imei = trim(input("request.imei"));//手机imei
        $os = trim(input("request.os"));//手机系统

        if ($os) {
            $os = strtolower($os);
        }

        $dataModel = new \app\admin\model\User();

        if (empty($code)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,请输入手机短信验证码';
            return json($return);
        }

        if (!checkPhone($uname)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }

        if (empty($pwd1)) {
            $return['err'] = 11000;
            $return['msg'] = '参数错误,登录密码不能够为空';
            return json($return);
        }

        if ($pwd1 != $pwd2) {
            $return['err'] = 11000;
            $return['msg'] = '对不起，两次密码输入不一致';
            return json($return);
        }


        $userInfo = $dataModel->getDataForWhere(array(
            'uname' => $uname,
            'is_delete' => 0
        ));

        $userInfocc = $dataModel->getDataForWhere(array(
            'uname' => $uname
        ));
        if (!empty($userInfo)) {
            $return['err'] = 900000;
            $return['msg'] = '对不起，账号已经存在，请直接登录';
            return json($return);
        }


        $ipwd = userPWD($pwd1);
        //查询短信验证码
        $tmsgcodeModel = new \app\admin\model\Tmsgcode();
        $tmsgcodeData = $tmsgcodeModel->getDataForWhere(array(
            'tel' => $uname,
            'types' => 1,//注册
        ));

        if (empty($tmsgcodeData)) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不存在';
            return json($return);
        }
        if ($tmsgcodeData['codes'] != $code) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不正确';
            return json($return);
        }
        if ($tmsgcodeData['uses'] > 0) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码已使用';
            return json($return);
        }

        $tcode = trim(input("request.tcode"));//推广码
        $acode = trim(input("request.acode"));//代理编号
        $agentAndParent = userAgentAndParent($tcode, $acode);

        $idata = array(
            'uname' => $uname,
            'tcode' => str_rand(),//新建用户自己推广码
            'agent_id' => $agentAndParent['agent_id'],
            'father_id' => $agentAndParent['father_id'],
            'pwd' => $ipwd,
            'ver' => $ver,
            'os' => $os,
            'is_delete'=>0,
            'imei' => $imei,
            'ctime' => date("Y-m-d H:i:s"),
            'group' => $this->default_group_id//普通用户组
        );
        if(!empty($userInfocc)){
            $dataModel = new \app\admin\model\User();
            $dataModel->updateData($idata,$userInfocc['id']);
            $userInfo = $dataModel->getDataForWhere(array(
                'uname' => $uname,
                'is_delete' => 0
            ));

            $authConfig = array(
                'id' => $userInfo['id'],
                'uname' => $userInfo['uname'],
                'nickname' => $userInfo['nickname'],
                'time' => time(),
            );
            $return['auth'] = userAuth($authConfig);
            $return['err'] = 0;
            $return['msg'] = '注册成功';
            return json($return);

        }
        $res = $dataModel->add($idata);

        if ($res) {
            $userInfo = $idata;
            $userInfo['id'] = $res;
            //给用户增加默认角色,为支持多角色设计
            addUserSystemGroup($userInfo['id'], $this->default_group_id);
            //
            $NewwindRoomModel = new \app\admin\model\NewwindRoom();
            $NewwindRoomModel->add(array(
                'uid' => $userInfo['id'],
                'ctime' => date("Y-m-d H:i:s"),
                'name' => "默认",
                'flags' => 1,
            ));
            //修改短信验证码为已经使用
            $tmsgcodeModel->updateDataForWhere(array(
                'mtime' => time(),
                'uses' => 1
            ), array('id' => $tmsgcodeData['id']));
            $authConfig = array(
                'id' => $userInfo['id'],
                'uname' => $userInfo['uname'],
                'nickname' => $userInfo['nickname'],
                'time' => time(),
            );
            $return['auth'] = userAuth($authConfig);
            $return['err'] = 0;
            $return['msg'] = '注册成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '注册失败';
            return json($return);
        }

    }

    /**
     * 找回密码
     * @return \think\response\Json
     */
    public function findpwd()
    {
        $uname = trim(input("request.tel"));//手机号
        $pwd = trim(input("request.pwd"));//新密码
        $code = trim(input("request.code"));//手机验证码
        $ver = trim(input("request.ver"));//app版本
        $imei = trim(input("request.imei"));//imea
        $os = trim(input("request.os"));//系统
        if ($os) {
            $os = strtolower($os);
        }

        if (empty($code)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,请输入手机短信验证码';
            return json($return);
        }
        //
        $tmsgcodeModel = new \app\admin\model\Tmsgcode();

        $tmsgcodeData = $tmsgcodeModel->getDataForWhere(array(
            'tel' => $uname,
            'types' => 2,//注册
        ));

        if (empty($tmsgcodeData)) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不存在';
            return json($return);
        }
        if ($tmsgcodeData['codes'] != $code) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不正确';
            return json($return);
        }
        if ($tmsgcodeData['uses'] > 0) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码已使用';
            return json($return);
        }
        //

        if (!checkPhone($uname)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }

        if (empty($pwd)) {
            $return['err'] = 11000;
            $return['msg'] = '参数错误,新密码不能够为空';
            return json($return);
        }
        $dataModel = new \app\admin\model\User();
        $userInfo = $dataModel->getDataForWhere(array(
            'uname' => $uname,
            'is_delete' => 0
        ));
        if (empty($userInfo)) {
            $return['err'] = 11000;
            $return['msg'] = '该手机号未注册，请先注册';
            return json($return);
        }
        $ipwd = userPWD($pwd);


        $tmsgcodeModel = new \app\admin\model\Tmsgcode();
        //修改短信验证码为已经使用
        $tmsgcodeModel->updateDataForWhere(array(
            'mtime' => time(),
            'uses' => 1
        ), array('id' => $tmsgcodeData['id']));
        $res = $dataModel->updateDataForWhere(array(
            'pwd' => $ipwd,
        ), array('id' => $userInfo['id']));

        $authConfig = array(
            'id' => $userInfo['id'],
            'uname' => $userInfo['uname'],
            'nickname' => $userInfo['nickname'],
            'last_access' => time(),
        );

        $return['auth'] = userAuth($authConfig);
        $return['err'] = 0;
        $return['msg'] = '操作成功';
        return json($return);
    }


    /**
     * 个性签名接口
     */
    public function sign()
    {
        $sign = trim(input("request.sign"));//签名内容
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        $userModel = new \app\admin\model\User();
        $data = array(
            'sign' => $sign
        );
        $userModel->updateData($data, $userInfo['id']);
        $return['err'] = 0;
        $return['msg'] = '操作成功';
        return json($return);
    }

    /**
     * 补充用户数据
     */
    public function addUserInfo()
    {
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }

        $sex = trim(input("request.sex"));//用户
        $bday = trim(input("request.bday"));//用户auth
        $height = trim(input("request.height"));//用户auth
        $weight = trim(input("request.weight"));//用户auth
        $nickname = trim(input("request.nickname"));//用户auth
        $sleep_option = trim(input("request.sleep_option"));//失眠类型
        $head = trim(input("request.head"));//失眠类型
        $model = new \app\admin\model\User();
        $update = array();
        if ($sex != "") {
            $update['sex'] = $sex;
        }
        if (!empty($bday)) {
            $update['bday'] = $bday;
        }
        if (!empty($height)) {
            $update['height'] = $height;
        }
        if (!empty($weight)) {
            $update['weight'] = $weight;
        }
        if (!empty($nickname)) {
            $update['nickname'] = $nickname;
        }
        if (!empty($sleep_option)) {
            $update['sleep_option'] = $sleep_option;
        }
        if (!empty($head)) {
            $update['head'] = $head;
        }
        if (empty($update)) {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            return json($return);
        }

        $flag = $model->updateData($update, $userInfo['id']);
        if ($flag || $flag == 0) {
            $return['err'] = 0;
            $return['msg'] = '操作成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            return json($return);
        }
    }

    /**
     * 上传头像接口
     */
    public function head()
    {
        header('Content-type: text/plain');
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        $tyName = "pic";
        $scenePic = request()->file('file');
        $path = 'static' . DS . 'uploads' . DS . 'images' . DS . $tyName;
        $fingerData = uploadPicture($scenePic, $path);
        $pic = '';
        $thumb = "";
        if ($fingerData['err'] == '0') {
            $pic = $fingerData['file']['url'];
            $width = 100;
            $height = 100;
            $thumb = changeImageSize($pic, $width, $height);

        } else {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            echo json_encode($return, true);
            exit;
        }


        $iData = array(
            'pic' => str_replace("\\", "/", $pic),
            'thumb' => str_replace("\\", "/", $thumb),
        );
        if (empty($iData['thumb'])) {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            echo json_encode($return, true);
            exit;
        }
        $userModel = new \app\admin\model\User();
        $resultFlag = $userModel->updateData(array('head' => $iData['thumb']), $userInfo['id']);
        if ($resultFlag || $resultFlag == 0) {
            $return['err'] = 0;
            $return['msg'] = '成功';
            $return['data'] = $iData;
            echo json_encode($return, true);
            exit;
        } else {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            echo json_encode($return, true);
            exit;
        }

    }

    /**
     * 手机短信快速登录，如果没有注册就需要马上注册一个账户
     * @return \think\response\Json
     */
    public function loginForCode()
    {
        $ver = trim(input("request.ver"));//app版本
        $imei = trim(input("request.imei"));//imei
        $os = trim(input("request.os"));//系统
        $uname = trim(input("request.uname"));//
        $code = trim(input("request.code"));//验证码
        if ($os) {
            $os = strtolower($os);
        }

        if (empty($code)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,请输入手机短信验证码';
            return json($return);
        }
        //判断验证码是否正确
        $tmsgcodeModel = new \app\admin\model\Tmsgcode();

        $tmsgcodeData = $tmsgcodeModel->getDataForWhere(array(
            'tel' => $uname,
            'types' => 3,//快捷登录
        ));

        if (empty($tmsgcodeData)) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不存在';
            return json($return);
        }
        if ($tmsgcodeData['codes'] != $code) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不正确';
            return json($return);
        }
        if ($tmsgcodeData['uses'] > 0) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码已使用';
            return json($return);
        }

        if (!checkPhone($uname)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }

        $userModel = new \app\admin\model\User();
        $where = array();
        $where['uname'] = $uname;
        $where['is_delete'] = 0;
        $userinfo = $userModel->getDataForWhere($where, '*');

        if (!empty($userinfo)) {//已有账号
            if ($userinfo['stat'] != 0) {
                $return = ['err' => 1000, 'msg' => '登录失败,账号被禁用', 'devMsg' => '登录失败，账号被禁用'];
                return json($return);
            }
        } else {//没有账号，新注册一个账号

            $tcode = trim(input("request.tcode"));//推广码
            $acode = trim(input("request.acode"));//代理编号
            $agentAndParent = userAgentAndParent($tcode, $acode);

            $newUser = array(
                'uname' => $uname,
                'tcode' => str_rand(),//新建用户自己推广码
                'agent_id' => $agentAndParent['agent_id'],
                'father_id' => $agentAndParent['father_id'],
                'pwd' => "",
                'ver' => $ver,
                'os' => $os,
                'imei' => $imei,
                'ctime' => date("Y-m-d H:i:s"),
                'group' => $this->default_group_id//普通用户组
            );
            $insertUserId = $userModel->add($newUser);
            if (empty($insertUserId)) {
                $return = ['err' => 1000, 'msg' => '登录失败', 'devMsg' => '登录失败'];
                return json($return);
            }
            //给用户增加默认角色,为支持多角色设计
            addUserSystemGroup($insertUserId, $this->default_group_id);
            $userinfo = getUserInfoForID($insertUserId);
        }


        //修改短信验证码为已经使用
        $tmsgcodeModel->updateDataForWhere(array(
            'mtime' => time(),
            'uses' => 1
        ), array('id' => $tmsgcodeData['id']));

        //记录登录日志
        $logdata = array(
            'ip' => get_client_ip(),
            'ctime' => time(),
            'uid' => $userinfo['id'],
            'ver' => $ver,
            'os' => $os,
            'imei' => $imei,
        );
        RecordLoginLog("loginlog", $logdata);

        $userinfo = filterUserInfoField($userinfo);
        $return = ['err' => 0, 'msg' => '登录成功', 'devMsg' => '登录成功', 'data' => $userinfo];
        $authConfig = array(
            'id' => $userinfo['id'],
            'uname' => $userinfo['uname'],
            'nickname' => $userinfo['nickname'],
            'time' => time(),
        );
        $return['auth'] = userAuth($authConfig);
        //记录登录信息
        recordClientVerAndType($userinfo, $_REQUEST['os'], $_REQUEST['ver']);
        return json($return);

    }


    /**
     * 绑定支付宝账号
     */
    public function bindAlipay()
    {
        $auth = trim(input("request.auth"));//用户auth
        $alipay_name = trim(input("request.alipay_name"));//支付宝
        $alipay_account = trim(input("request.alipay_account"));//支付宝账号
        $code = trim(input("request.code"));//验证码
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        if (empty($alipay_name)) {
            $return = ['err' => 1, 'msg' => '操作失败,支付宝姓名为空', 'devMsg' => '操作失败，参数错误[alipay_name]'];
            return json($return);
        }
        if (empty($alipay_account)) {
            $return = ['err' => 1, 'msg' => '操作失败,支付宝账号为空', 'devMsg' => '操作失败，参数错误[alipay_account]'];
            return json($return);
        }
        //验证手机短信验证码
        $checkResult = checkPhoneCode($userInfo['uname'], $code, 4);//1注册  2 找回密码 3快捷登录 4、绑定支付宝提现账号
        if ($checkResult['err'] > 0) {
            return json($checkResult);
        }
        $update = array(
            'alipay_name' => $alipay_name,
            'alipay_account' => $alipay_account,
        );
        $userModel = new \app\admin\model\User();
        $flag = $userModel->updateData($update, $userInfo['id']);
        if ($flag || $flag == 0) {
            setPhoneCodeUsed($checkResult['data']['id']);
            $return['err'] = 0;
            $return['msg'] = '操作成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['msg'] = '操作失败';
            return json($return);
        }
    }


    /**
     * 绑定微信
     * @return \think\response\Json
     */
    public function bindwx()
    {
        $ver = trim(input("request.ver"));//app版本
        $imei = trim(input("request.imei"));//imei
        $os = trim(input("request.os"));//系统
        $uname = trim(input("request.uname"));//手机号
        $wechat_openid = trim(input("request.openid"));//微信openid
        $code = trim(input("request.code"));//验证码

        if ($os) {
            $os = strtolower($os);
        }

        if (empty($wechat_openid)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,openid为空';
            return json($return);
        }

        if (empty($code)) {
            $return['err'] = 10000;
            $return['msg'] = '参数错误,请输入手机短信验证码';
            return json($return);
        }

        //判断验证码是否正确
        $tmsgcodeModel = new \app\admin\model\Tmsgcode();
        $tmsgcodeData = $tmsgcodeModel->getDataForWhere(array(
            'tel' => $uname,
            'types' => 5,//快捷登录
        ));

        if (empty($tmsgcodeData)) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不存在';
            return json($return);
        }
        if ($tmsgcodeData['codes'] != $code) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码不正确';
            return json($return);
        }
        if ($tmsgcodeData['uses'] > 0) {
            $return['err'] = 10000;
            $return['msg'] = '短信验证码已使用';
            return json($return);
        }

        if (!checkPhone($uname)) {
            $return['err'] = 10001;
            $return['msg'] = '输入的手机号不正确，请输入正确的手机号';
            return json($return);
        }

        $userModel = new \app\admin\model\User();
        $where = array();
        $where['uname'] = $uname;
        $where['is_delete'] = 0;
        $userinfo = $userModel->getDataForWhere($where, '*');

        if (!empty($userinfo)) {//已有账号
            if ($userinfo['stat'] != 0) {
                $return = ['err' => 1000, 'msg' => '绑定失败,账号被禁用', 'devMsg' => '绑定失败，账号被禁用'];
                return json($return);
            }
            $updateData = array(
                'wechat_openid' => $wechat_openid,
            );
            $userinfo['wechat_openid'] = $wechat_openid;
            $userModel->updateData($updateData, $userinfo['id']);
        } else {//没有账号，新注册一个账号


            $tcode = trim(input("request.tcode"));//推广码
            $acode = trim(input("request.acode"));//代理编号
            $agentAndParent = userAgentAndParent($tcode, $acode);


            $newUser = array(
                'uname' => $uname,
                'tcode' => str_rand(),//新建用户自己推广码
                'agent_id' => $agentAndParent['agent_id'],
                'father_id' => $agentAndParent['father_id'],
                'pwd' => "",
                'ver' => $ver,
                'os' => $os,
                'imei' => $imei,
                'wechat_openid' => $wechat_openid,
                'ctime' => date("Y-m-d H:i:s"),
                'group' => $this->default_group_id//普通用户组
            );
            $insertUserId = $userModel->add($newUser);
            if (empty($insertUserId)) {
                $return = ['err' => 1000, 'msg' => '绑定失败', 'devMsg' => '绑定失败'];
                return json($return);
            }
            addUserSystemGroup($insertUserId, $this->default_group_id);
            $userinfo = getUserInfoForID($insertUserId);
        }


        //修改短信验证码为已经使用
        $tmsgcodeModel->updateDataForWhere(array(
            'mtime' => time(),
            'uses' => 1
        ), array('id' => $tmsgcodeData['id']));

        //记录登录日志
        $logdata = array(
            'ip' => get_client_ip(),
            'ctime' => time(),
            'uid' => $userinfo['id'],
            'ver' => $ver,
            'os' => $os,
            'imei' => $imei,
        );
        RecordLoginLog("loginlog", $logdata);
        $userinfo = filterUserInfoField($userinfo);
        $return = ['err' => 0, 'msg' => '绑定成功', 'devMsg' => '绑定成功', 'data' => $userinfo];
        $authConfig = array(
            'id' => $userinfo['id'],
            'uname' => $userinfo['uname'],
            'nickname' => $userinfo['nickname'],
            'time' => time(),
        );
        $return['auth'] = userAuth($authConfig);
        return json($return);
    }

    /**
     * 用户与用户之间 添加关注
     */
    public function addFriend()
    {
        $auth = trim(input("request.auth"));//用户auth
        $fuid = trim(input("request.fuid"));
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        if (empty($fuid)) {
            $return = ['err' => 1, 'msg' => '操作失败,被关注者用户不正确', 'devMsg' => '操作失败，参数错误[fuid]'];
            return json($return);
        }
        $fuserInfo = getUserInfoForID($fuid);
        if (empty($fuserInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,被关注用户不正确', 'devMsg' => '操作失败，参数错误[fuid]'];
            return json($return);
        }
        if ($fuid == $userInfo['id']) {
            $return = ['err' => 1, 'msg' => '操作失败,不能自己关注自己', 'devMsg' => '操作失败'];
            return json($return);
        }
        $flag = isFriend($userInfo['id'], $fuid);
        if ($flag) {
            $return = ['err' => 1, 'msg' => '操作失败,该用户您已经关注', 'devMsg' => '操作失败'];
            return json($return);
        }
        if (addFriend($userInfo['id'], $fuid)) {
            $return = ['err' => 0, 'msg' => '操作成功', 'devMsg' => "操作成功"];
            return json($return);
        } else {
            $return = ['err' => 1, 'msg' => '操作失败', 'devMsg' => ''];
            return json($return);
        }
    }


    /**
     * 用户与用户之间 取消关注
     */
    public function cancelFriend()
    {
        $auth = trim(input("request.auth"));//用户auth
        $fuid = trim(input("request.fuid"));//
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,未登录', 'devMsg' => '操作失败，参数错误[auth]'];
            return json($return);
        }
        if (empty($fuid)) {
            $return = ['err' => 1, 'msg' => '操作失败,被关注者用户不正确', 'devMsg' => '操作失败，参数错误[fuid]'];
            return json($return);
        }
        $fuserInfo = getUserInfoForID($fuid);
        if (empty($fuserInfo)) {
            $return = ['err' => 1, 'msg' => '操作失败,被关注用户不正确', 'devMsg' => '操作失败，参数错误[fuid]'];
            return json($return);
        }
        if ($fuid == $userInfo['id']) {
            $return = ['err' => 1, 'msg' => '操作失败,不能自己取消关注自己', 'devMsg' => '操作失败'];
            return json($return);
        }
        $flag = isFriend($userInfo['id'], $fuid);
        if ($flag == 0) {
            $return = ['err' => 1, 'msg' => '操作失败,该用户您已经取消关注了', 'devMsg' => '操作失败'];
            return json($return);
        }
        if (cancelFriend($userInfo['id'], $fuid)) {
            $return = ['err' => 0, 'msg' => '操作成功', 'devMsg' => "操作成功"];
            return json($return);
        } else {
            $return = ['err' => 1, 'msg' => '操作失败', 'devMsg' => ''];
            return json($return);
        }
    }


    /**
     * 获取我的粉丝列表接口，即关注我的
     */
    public function myFans()
    {
        $auth = trim(input("request.auth"));//用户auth
        $page = trim(input("request.page"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '获取失败,未登录', 'devMsg' => '获取失败，参数错误[auth]'];
            return json($return);
        }
        $pagesize = trim(input("pagesize"));//每页条数
        if (!empty($pagesize)) {
            $this->pagesize = $pagesize;
        }
        if (empty($page)) {
            $page = 1;
        }
        $w = array('id' => $userInfo['id']);
        $userModel = new \app\admin\model\UserFriend();

        $sql = "select 
        a.id as uid,
        a.uname as uname,
        a.nickname as nickname,
        a.head as head,
        a.sex as sex,
        a.bday as bday,
        a.height as height,
        a.weight as weight,
        b.ctime as ctime
        from  t_user as a,t_user_friend as b
        where a.id = b.uid and b.fuid = {$userInfo['id']} order by b.id desc ";

        $lists = $userModel->listsSimpleForSQL($sql, $this->pagesize, $page);

        $return['err'] = 0;
        $return['msg'] = '获取成功';
        $return['data'] = $lists;
        return json($return);
    }

    /**
     * 获取我的粉丝列表接口，即关注我的
     */
    public function myGuanzhu()
    {
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '获取失败,未登录', 'devMsg' => '获取失败，参数错误[auth]'];
            return json($return);
        }
        $pagesize = trim(input("pagesize"));//每页条数
        if (!empty($pagesize)) {
            $this->pagesize = $pagesize;
        }
        $page = trim(input("request.page"));//用户auth
        if (empty($page)) {
            $page = 1;
        }
        $w = array('id' => $userInfo['id']);
        $userModel = new \app\admin\model\UserFriend();

        $sql = "select 
        a.id as uid,
        a.uname as uname,
        a.nickname as nickname,
        a.head as head,
        a.sex as sex,
        a.bday as bday,
        a.height as height,
        a.weight as weight,
        b.ctime as ctime
        from  t_user as a,t_user_friend as b
        where a.id = b.fuid and b.uid = {$userInfo['id']} order by b.id desc ";
        $lists = $userModel->listsSimpleForSQL($sql, $this->pagesize, $page);
        $return['err'] = 0;
        $return['msg'] = '获取成功';
        $return['data'] = $lists;
        return json($return);
    }

    /**
     * 获取我最后一次购买商品的收获地址
     * @return \think\response\Json
     */
    public function getMyLastAddress()
    {
        $auth = trim(input("request.auth"));//用户auth
        $userInfo = checkLoginExp($auth);
        if (empty($userInfo)) {
            $return = ['err' => 1, 'msg' => '获取失败,未登录', 'devMsg' => '获取失败，参数错误[auth]'];
            return json($return);
        }

        $w = array('uid' => $userInfo['id'], 'ty' => 1);
        $model = new \app\admin\model\PayOrder();
        $list = $model->getDataForWheres($w, "*", "id desc", "1");
        $addressInfo = array(
            't_name' => "",
            't_phone' => "",
            't_provice' => "",
            't_city' => "",
            't_area' => "",
            't_address' => "",
            't_zipcode' => "",
        );
        if (!empty($list)) {
            $tempInfo = $list[0];
            $addressInfo['t_name'] = $tempInfo['t_name'];
            $addressInfo['t_phone'] = $tempInfo['t_phone'];
            $addressInfo['t_provice'] = $tempInfo['t_provice'];
            $addressInfo['t_city'] = $tempInfo['t_city'];
            $addressInfo['t_area'] = $tempInfo['t_area'];
            $addressInfo['t_address'] = $tempInfo['t_address'];
            $addressInfo['t_zipcode'] = $tempInfo['t_zipcode'];
        }
        $return['err'] = 0;
        $return['msg'] = '获取成功';
        $return['data'] = $addressInfo;
        return json($return);
    }

    public function t()
    {
        (new \app\admin\model\Debug())->add([
                'txt' => "pppp",
                'ty' => 100,
                'ctime' => date("Y-m-d H:i:s")
            ]
        );
    }

    public function ts()
    {

        $source = "/uploads/10/files/20190828/9962f03e674b21cdb5ff8f84ca0ca14b.png";
        libreofficeConvertToPDF($source, "", "", true);
    }

    public function runDemo($phone, $pwd)
    {
        $dir = dirname(realpath(APP_PATH));
        $dir = $dir . DIRECTORY_SEPARATOR . 'public';
        $file = $dir . DIRECTORY_SEPARATOR . "ttt.txt";
        for ($i = 0; $i < 10; $i++) {
            file_put_contents($file, date("Y-m-d h:i:s") . ":" . $phone . ":" . $pwd . "\r\n", FILE_APPEND);
            sleep(1);
        }
    }

    public function tsn()
    {
        import("myCal.AsyncHook#class", VENDOR_PATH);
        //方式一：
        \AsyncHook::hook(array($this, 'runDemo'), array(trim("13547983127"), "123321"));//面向对象调用
        //方式二：
//        \AsyncHook::hook('\app\api\controller\User::runDemo', array(trim("135666666"), "123123"));//面向过程方式调用
        $return['err'] = 0;
        $return['msg'] = '获取成功';
        return json($return);
    }


    public function com2user()
    {
        $openid = "oH-8p47kKTO-4mZ6iP7xfiTVI1yM";
        $res = wechatCompanyPayUser(1001, 't001', 0.01, $openid);
        print_r($res);
    }

    public function aa()
    {
        $msg = [
            'touser' => 'oH-8p47kKTO-4mZ6iP7xfiTVI1yM',
            'msgtype' => 'text',
            'content' => 'text',
        ];
        $res = sendWechatCustomerServiceMsg($msg, 1001, 1);
        print_r($res);
    }

    public function bb()
    {
        $openid = 'oKUIN5N0Sono2BdKVgu4QnQgraUI';
        $templateID = "o-Zp6QCQfc_rHHCsBETgxuzSsPmypKzhf_QZXvTF_hw";

        $hosp_id = 1001;
        $messageBody = array("title" => $val['title'], 'conts' => $val['conts'], 'date' => $val['date']);
        $res = wechatSendTemplateMsg($val['openid'], $val['templateid'], $messageBody, $hosp_id, 1);
    }

    public function cc()
    {
        $openid = 'okaQw5aCwyi3RyDSzqR5aFKfRpuQ';
        $templateID = "sckWi5lmo-0bVCybOycEwViV5hYi2lNcu1JdmSEiXoA";
        $page = "/pages/index/index";
        $hosp_id = 1001;
        $client = 2;
        $miniprogram_state = "trial";


        $data = array(
            'name' => '张珊',
            'desc' => '我生病了',
            'service' => '快速问诊',
            'orderInfo' => '待接单',
            'date' => date("Y-m-d H:i:s")
        );
        $templateData = '{
           "thing1": {
             "value": "' . $data['name'] . '"
         },
         "thing2": {
             "value":"' . $data['desc'] . '"
         },
         "thing4": {
             "value": "' . $data['service'] . '"
         },
         "thing5": {
             "value": "' . $data['orderInfo'] . '"
         },
         "date3": {
             "value": "' . $data['date'] . '"
         }
     }';
        $res = wechatSendSubscribeTemplateMsg($hosp_id, $client, $openid, $templateID, $page, $miniprogram_state, $templateData);
        print_r($res);
    }

    public function dd()
    {
        $str = '{"openid":"okaQw5aCwyi3RyDSzqR5aFKfRpuQ","order_sn":"h2020052655515354","templateID":"sckWi5lmo-0bVCybOycEwViV5hYi2lNcu1JdmSEiXoA","page":"\/pages\/index\/index","hosp_id":1001,"client":2,"miniprogram_state":"trial","template_data":"{\n           \"thing1\": {\n             \"value\": \"\u54c8\u54c8 \u7537 2006-05-26\"\n         },\n         \"thing2\": {\n             \"value\":\"\u5173\u95ed\u63a5\u8bca\"\n         },\n         \"thing4\": {\n             \"value\": \"\u5feb\u901f\u95ee\u8bca\"\n         },\n         \"thing5\": {\n             \"value\": \"\u5df2\u63a5\u5355\"\n         },\n         \"date3\": {\n             \"value\": \"2020-05-28 17:23:09\"\n         }\n     }"}';
        $param = json_decode($str, true);
        $res = wechatSendSubscribeTemplateMsg($param['hosp_id'], $param['client'], $param['openid'],
            $param['templateID'], $param['page'], $param['miniprogram_state'], $param['template_data']);
        if ($res['err']) {
            addTaskLog(array(
                'taskname' => $param['order_sn'],
                'key' => time(),
                'param' => json_encode($param, true),
                'result' => "ok",
                'ctime' => date("Y-m-d H:i:s"),
            ));
        } else {
            addTaskLog(array(
                'taskname' => $param['order_sn'],
                'key' => time(),
                'param' => json_encode($param, true),
                'result' => $res['msg'],
                'ctime' => date("Y-m-d H:i:s"),
            ));
        }
        print_r($res);
    }

    public function testWebchatApp()
    {
        import("myCal.WebChatApp#class", VENDOR_PATH);
        $hander = \WebChatApp::getInstance();
        $token_info = $hander->getAccessToken();
        if ($token_info['err'] == 0) {
            $file_path = dirname(realpath(APP_PATH)) . "/public" . "/static/sleepSum/sleepHtml/images/logo.png";
            $data = array(
                'articles' => [
                    array(
                        "title" => "成都的朋友们欢迎您！",
                        "thumb_media_id" => 'http://mmbiz.qpic.cn/mmbiz_png/EGG66mTvpRyMEMq4TjE9TGj1nNG0KWIiaNN2iaFfJVgUN11cVgPQPez5ww2dYROsNFZM0KHCBwWILKENKMc3mncQ/0',
                        "author" => 'xgl',
                        "digest" => "",
                        "show_cover_pic" => 1,
                        "content" => "欢迎到来",
                        "content_source_url" > 'http://www.qnchisu.com',
                        "need_open_comment" => 1,
                        "only_fans_can_comment" => 1
                    ),
                ]
            );
            $result = $hander->uploadMedia($token_info['data'], 1, $data);
            print_r($result);
        }
    }

    public function xglabc()
    {
        import("myCal.WebChatApp#class", VENDOR_PATH);
        $hander = \WebChatApp::getInstance();
        $token_info = $hander->getAccessToken();
        if ($token_info['err'] == 0) {
            $file_path = dirname(realpath(APP_PATH)) . "/public" . "/static/sleepSum/sleepHtml/images/logo.png";
            $result = $hander->uploadMedia($token_info['data'], 2, $file_path);
            print_r($result);
        }
    }

    public function slfile()
    {
        echo date("Y-m-d H:i:s");
        echo date_default_timezone_get();
    }

    public function ddd()
    {
        $date = "2020-7-25";
        $ty = 2;

    }

    public function ggg()
    {
        $userInfo = array('id' => 100148);
        $dataid = 3553;
//        $result = recordFiles($userInfo, $dataid, 0);
        $data = loadSummary($userInfo, $dataid, 0);
//        $result = analysisSummaryData($data, $userInfo['id'], $dataid, 0);
//        $data = loadCurves($userInfo, $dataid, 0);
        print_r($data);

    }


    /**
     * 获取微信小程序手机号码
     * @return \think\response\Json
     */
    public function getWechatPhone()
    {


        $access_token = trim($_REQUEST['openid']);
        $_hosp = 1;
        if (empty($access_token)) {
            $return['err'] = 10005;
            $return['msg'] = 'openid不正确';
            echo json_encode($return, true);
            exit;
        }
        $encryptedData = trim(input("encryptedData"));
        $session_key = trim(input("session_key"));
        $iv = trim(input("iv"));
        if (empty($encryptedData)) {
            $return = ['err' => 1, 'msg' => '参数错误', 'devMsg' => ''];
            return json($return);
        }
        if (empty($iv)) {
            $return = ['err' => 1, 'msg' => '参数错误', 'devMsg' => ''];
            return json($return);
        }

        if (empty($session_key)) {
            $return = ['err' => 1, 'msg' => '参数错误', 'devMsg' => ''];
            return json($return);
        }
        $session_key = stripslashes($session_key);

        $res = WechatPhoneDecrpt($encryptedData, $iv, $session_key, $_hosp);
        if ($res) {
            $return['err'] = 0;
            $return['data'] = array(
                'phoneNumber' => $res['phoneNumber'],
                'purePhoneNumber' => $res['purePhoneNumber'],
                'countryCode' => $res['countryCode'],
            );
            $return['msg'] = '成功';
            return json($return);
        } else {
            $return['err'] = 1;
            $return['data'] = $res;
            $return['msg'] = '失败';
            return json($return);
        }
    }


    public function testRsa()
    {
        RsaEncryptDataTest();
    }

}


